package com.xx.entity;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.util.List;

@Data
@Schema(name = "PageResult",description = "分页实体")
public class PageResult<T> {
    @Schema(name = "total" ,description = "总记录数")
    private long total;        // 总记录数
    @Schema(name = "size" ,description = "每页显示的记录数")
    private long size;         // 每页显示的记录数
    @Schema(name = "current" ,description = "当前页码")
    private long current;      // 当前页码
    @Schema(name = "records" ,description = "总页数")
    private long pages;        // 总页数
    @Schema(name = "records" ,description = "数据列表")
    private List<T> records;   // 数据列表

    /**
     * 构造函数，基于 IPage 封装分页结果
     */
    public PageResult(IPage<T> page) {
        this.total = page.getTotal();
        this.size = page.getSize();
        this.current = page.getCurrent();
        this.pages = page.getPages();
        this.records = page.getRecords();
    }

    /**
     * 静态方法，方便直接从 IPage 创建 PageResult
     */
    public static <T> PageResult<T> of(IPage<T> page) {
        return new PageResult<>(page);
    }
}
